#ifndef FILEDOWNLOADER_H
#define FILEDOWNLOADER_H

#include <QObject>

class QUrl;
class QNetworkReply;
namespace Jcr
{
class FileDownloaderPrivate;
class FileDownloader : public QObject
{
    Q_OBJECT
public:
    explicit FileDownloader(const QUrl& url, QObject *parent = nullptr);
    explicit FileDownloader(QObject* parent = nullptr);
    virtual ~FileDownloader();

    void setUrl(const QUrl& url);
    QUrl url() const;

    void setSaveDir(const QString& saveDir);
    QString saveDir() const;

    void setSaveName(const QString& saveName);
    QString saveName() const;

    QString localPath() const;

public slots:
    void start();
    void abort();

signals:
    void percentCompleted(float percent);
    void finished();

private slots:
    void onReply(QNetworkReply* reply);
    void onDownloadProgress(qint64 receivedBytes, qint64 totalBytes);

private:
    FileDownloaderPrivate* d_ptr;
    Q_DISABLE_COPY(FileDownloader)
};

} // namespace
#endif // FILEDOWNLOADER_H
